package com.joysuch.wwyt.core.repository;

import com.joysuch.wwyt.core.entity.BaseCreditCardRecord;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;

import java.util.Date;

public interface BaseCreditCardRecordDao extends JpaRepository<BaseCreditCardRecord, Long>, QuerydslPredicateExecutor<BaseCreditCardRecord> {
    public Page<BaseCreditCardRecord> findAll(Specification<BaseCreditCardRecord> spec, Pageable pageable);

    @Query(value = "SELECT * FROM wwyt_base_credit_card_record WHERE delete_flag = '0' AND  code =?1 AND org_code =?2 AND type_flag =?3",nativeQuery = true)
    BaseCreditCardRecord findByCodeAndOrgCodeAndTypeFlag(Integer code, String orgCode,Integer typeFlag);

    @Query(value = "SELECT MAX(create_time) FROM wwyt_base_credit_card_record WHERE delete_flag = '0' AND org_code =?1 AND type_flag=?2",nativeQuery = true)
    Date getMaxCreateTime(String companyCode,Integer typeFlag);
}
